ARD2  1.00 for Rev B. Hardware
Airbag Reference Demonstrator using MPC5604P
Miranda.h File Reference

Driver for upcoming roll-over sensor. More...

Go to the source code of this file.

Defines

#define TRUE   (1u)
#define CLEAR   (0u)
#define BITS_IN_NIBBLE   (4u)
#define BITS_IN_BYTE   (8u)
#define BITS_IN_16   (16u)
#define BYTES_IN_16   (2u)
#define BYTES_IN_32   (4u)
#define BIT_DEFINITION
#define BIT0   (1u << 0u)
#define BIT1   (1u << 1u)
#define BIT2   (1u << 2u)
#define BIT3   (1u << 3u)
#define BIT4   (1u << 4u)
#define BIT5   (1u << 5u)
#define BIT6   (1u << 6u)
#define BIT7   (1u << 7u)
#define BIT8   (1u << 8u)
#define BIT9   (1u << 9u)
#define BIT10   (1u << 10)
#define BIT11   (1u << 11)
#define BIT12   (1u << 12)
#define BIT13   (1u << 13)
#define BIT14   (1u << 14)
#define BIT15   (1u << 15)
#define BIT16   (1u << 16)
#define BIT17   (1u << 17)
#define BIT18   (1u << 18)
#define BIT19   (1u << 19)
#define BIT20   (1u << 20)
#define BIT21   (1u << 21)
#define BIT22   (1u << 22)
#define BIT23   (1u << 23)
#define BIT24   (1u << 24)
#define BIT25   (1u << 25)
#define BIT26   (1u << 26)
#define BIT27   (1u << 27)
#define BIT28   (1u << 28)
#define BIT29   (1u << 29)
#define BIT30   (1u << 30)
#define BIT31   (1u << 31)
#define MIRANDA_MEMORY_MAP_SIZE   (0x2Eu)
#define MIRANDA_SN_0   (0x00u << 5u)
#define MIRANDA_SN_1   (0x02u << 5u)
#define MIRANDA_ID_0   (0x04u << 5u)
#define MIRANDA_ID_1   (0x06u << 5u)
#define MIRANDA_DEVCFG_0   (0x08u << 5u)
#define MIRANDA_DEVCFG_1   (0x0Au << 5u)
#define MIRANDA_CD_0C   (0x0Cu << 5u)
#define MIRANDA_CD_0E   (0x0Eu << 5u)
#define MIRANDA_CD_10   (0x10u << 5u)
#define MIRANDA_CD_12   (0x12u << 5u)
#define MIRANDA_CD_14   (0x14u << 5u)
#define MIRANDA_CD_16   (0x16u << 5u)
#define MIRANDA_CD_18   (0x18u << 5u)
#define MIRANDA_CD_1A   (0x1Au << 5u)
#define MIRANDA_CD_1C   (0x1Cu << 5u)
#define MIRANDA_CD_1E   (0x1Eu << 5u)
#define MIRANDA_DEVSTAT   (0x20u << 5u)
#define MIRANDA_DEVCTL   (0x22u << 5u)
#define MIRANDA_TEST   (0x24u << 5u)
#define MIRANDA_RATE_X   (0x26u << 5u)
#define MIRANDA_ACC_Y   (0x28u << 5u)
#define MIRANDA_ACC_Z   (0x2Au << 5u)
#define MIRANDA_TEMP   (0x2Cu << 5u)
#define MIRANDA_COUNT   (0x2Eu << 5u)
#define MIRANDA_MEMORY_MAP_SIZE_P2   (0x1Fu)
#define MIRANDA_RATE_X_P2   (0x01u << 10u)
#define MIRANDA_ACC_Y_P2   (0x05u << 10u)
#define MIRANDA_ACC_Z_P2   (0x06u << 10u)
#define MIRANDA_TEMP_P2   (0x07u << 10u)
#define MIRANDA_BANK_P2   (0x08u << 10u)
#define MIRANDA_TEST_P2   (0x15u << 10u)
#define MIRANDA_RESET_P2   (0x16u << 10u)
#define MIRANDA_SENS_SYNC_P2   (0x18u << 10u)
#define MIRANDA_DEVSTAT_P2   (0x19u << 10u)
#define MIRANDA_DEVCTL_P2   (0x1Au << 10u)
#define MIRANDA_COUNT_P2   (0x1Bu << 10u)
#define MIRANDA_DEV_ID_P2   (0x1Du << 10u)
#define MIRANDA_SN_0_P2   (0x10u << 10u)
#define MIRANDA_SN_1_P2   (0x11u << 10u)
#define MIRANDA_ID_0_P2   (0x12u << 10u)
#define MIRANDA_ID_1_P2   (0x13u << 10u)
#define MIRANDA_DEVCFG_0_P2   (0x14u << 10u)
#define MIRANDA_DEVCFG_1_P2   (0x15u << 10u)
#define MIRANDA_CD_0C_P2   (0x16u << 10u)
#define MIRANDA_CD_0E_P2   (0x17u << 10u)
#define MIRANDA_CD_10_P2   (0x18u << 10u)
#define MIRANDA_CD_12_P2   (0x19u << 10u)
#define MIRANDA_CD_14_P2   (0x1Au << 10u)
#define MIRANDA_CD_16_P2   (0x1Bu << 10u)
#define MIRANDA_CD_18_P2   (0x1Cu << 10u)
#define MIRANDA_CD_1A_P2   (0x1Du << 10u)
#define MIRANDA_CD_1C_P2   (0x1Eu << 10u)
#define MIRANDA_CD_1E_P2   (0x1Fu << 10u)
#define MIRANDA_READ_REGISTER   (0x00u)
#define MIRANDA_WRITE_REGISTER   (0x80u)
#define MIRANDA_READ_X   (0x0001u)
#define MIRANDA_READ_Y   (0x0002u)
#define MIRANDA_READ_Z   (0x0003u)
#define MIRANDA_READ_ACCEL   (0x2000u)
#define MIRANDA_INVALID_PARITY   (0x10u)
#define MIRANDA_TIMED_OUT   (0x20u)
#define MIRANDA_INVALID_MEMORY_LOCATION   (0x40u)
#define MIRANDA_ERROR_PROTOCOL   (0x80u)
#define MIRANDA_EXCEPTION   (0x11u)
#define MIRANDA_INVALID_CRC   (0x12u)
#define MIRANDA_EXCEPTION_MASK   (0x07u)
#define MIRANDA_INTERNAL_ERROR   (0x03u)
#define MIRANDA_SPI_FAULT   (0x05u)
#define MIRANDA_MISO_COMPARE_FAULT   (0x06u)
#define MIRANDA_RAW_INERTIAL_MASK_UPPER   (0x03FFu)
#define MIRANDA_RAW_INERTIAL_MASK_LOWER   (0xFC00u)
#define PROTOCOL_0   0
#define PROTOCOL_1   1
#define PROTOCOL_2   2
#define N_ELEMENTS(X)   (sizeof(X)/sizeof(*(X)))

Functions

uint8_t u8fnMirandaReadRegister (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, uint16_t u16Register, uint16_t *pu16DataRead, const uint8_t cu8Protocol)
 Reads one register from Miranda.
uint8_t u8fnMirandaWriteRegister (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, uint16_t u16Register, uint16_t u16ValueToWrite, uint16_t *pu16DataRead, const uint8_t cu8Protocol)
 Writes to one register of the MMIRANDA.
uint8_t u8fnMirandaReset (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8Protocol)
 Performs a soft-reset of the device.
uint8_t u8fnMirandaReadAccelRegisters (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8Protocol)
 Reads accelerations by mean of registers readback.
uint8_t u8fnMirandaReadAllRegisters (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8Protocol)
 Reads all registers content.
uint8_t u8fnMirandaReadAccelSPI (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8Axis, uint16_t *pu16AccelResults)
 Reads acceleration by mean of SPI extraction (Protocol1 only)
uint8_t u8fnMirandaBatchOp (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint16_t *pu16DataToSend, uint16_t *pu16UnfilteredDataReceived, uint8_t u8Size, const uint8_t cu8Protocol)
 Sends n transfers to the device, and reads-back as well.
uint8_t u8fnMirandaExtractRegisterResponse (const uint16_t *pu16RawResponse, uint16_t *pu16Response, uint8_t u8Size, const uint8_t cu8Protocol)
 Extracts 8-bit information from raw data.
uint8_t u8fnMirandaExtractAccelResponse (const uint16_t *pu16RawResponse, uint16_t *pu16Response, uint8_t u8Size)
 Extracts 10-bit accel information from raw data.

Variables

const uint16_t cau16MirandaReadAllRegisters []
const uint16_t cau16MirandaReset []
const uint16_t cau16MirandaPerformAccelReading []
const uint16_t cau16MirandaPerformAccelReadingSPI []

Detailed Description

Driver for upcoming roll-over sensor.

Copyright (c) 2011 Freescale Semiconductor Freescale Confidential Proprietary

Author:
Freescale Semiconductor
SASD Automotive
R54967
Version:
Date:
Warning:
(If needed)

History:


Function Documentation

uint8_t u8fnMirandaBatchOp ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint16_t *  pu16DataToSend,
uint16_t *  pu16UnfilteredDataReceived,
uint8_t  u8Size,
const uint8_t  cu8Protocol 
)

Sends n transfers to the device, and reads-back as well.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
pu16DataToSend,:Pointer to complete message to send. Parity is calculated within the function. Constant tables in this file should be used accordingly.
pu16UnfilteredDataReceived,:Pointer to where part's response should be stored. This is the complete response, no filters.
u8Size,:Number of words to send/receive.
cu8Protocol,:Communication protocol activated.
Returns:
Status. Clear when no error found, otherwise errors as defined in this same file.
uint8_t u8fnMirandaExtractAccelResponse ( const uint16_t *  pu16RawResponse,
uint16_t *  pu16Response,
uint8_t  u8Size 
)

Extracts 10-bit accel information from raw data.

Parameters:
pu16RawResponse,:pointer to 16-bit, unfiltered response.
pu16Response,:pointer to where filtered data should be stored.
u8Size,:Size of raw responses to filter.
Returns:
Status. Clear when no error found, otherwise errors as defined in this same file.
uint8_t u8fnMirandaExtractRegisterResponse ( const uint16_t *  pu16RawResponse,
uint16_t *  pu16Response,
uint8_t  u8Size,
const uint8_t  cu8Protocol 
)

Extracts 8-bit information from raw data.

Parameters:
pu16RawResponse,:pointer to 16-bit, unfiltered response.
pu8Response,:pointer to where filtered data should be stored.
u8Size,:Size of raw responses to filter.
cu8Protocol,:Communication protocol activated.
Returns:
Status. Clear when no error found, otherwise errors as defined in this same file.
uint8_t u8fnMirandaReadAccelRegisters ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8Protocol 
)

Reads accelerations by mean of registers readback.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
cu8Protocol,:Communication protocol activated.
Returns:
Status. Clear when no error found, non-zero otherwise. This status byte is actually the read value from the DEVSTAT register within the device.
uint8_t u8fnMirandaReadAccelSPI ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8Axis,
uint16_t *  pu16AccelResults 
)

Reads acceleration by mean of SPI extraction (Protocol1 only)

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
cu8Axis,:1 for X, 2 for Y, 3 for Z. Any other value will result in an X-axis reading.
pu16AccelResults,:Pointer to location where accel reading(s) will be stored.
Returns:
Status. Clear when no error found, otherwise errors as defined in Miranda Exception codes.
uint8_t u8fnMirandaReadAllRegisters ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8Protocol 
)

Reads all registers content.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
cu8Protocol,:Communication protocol activated.
Returns:
Status. Clear when no error found, non-zero otherwise. This status byte is actually the read value from the DEVSTAT register within the device.
uint8_t u8fnMirandaReadRegister ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
uint16_t  u16Register,
uint16_t *  pu16DataRead,
const uint8_t  cu8Protocol 
)

Reads one register from Miranda.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
u16Register,:Address of the register to read with LSB in BIT21. For simplicity, use the #defines in this same file.
pu16DataRead,:Pointer to where data read should be stored.
cu8Protocol,:Communication protocol activated.
Returns:
Status. Clear when no error found, otherwise errors as defined in Miranda Exception codes.
uint8_t u8fnMirandaReset ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8Protocol 
)

Performs a soft-reset of the device.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
cu8Protocol,:Communication protocol activated.
Returns:
Status. Clear when no error found, non-zero otherwise. This status byte is actually the read value from the DEVCFG register within the device.
uint8_t u8fnMirandaWriteRegister ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
uint16_t  u16Register,
uint16_t  u16ValueToWrite,
uint16_t *  pu16DataRead,
const uint8_t  cu8Protocol 
)

Writes to one register of the MMIRANDA.

Parameters:
cu8DSPIInstance,:DSPI Instance to use.
cu8ChipSelect,:ChipSelect mask to be used.
u16Register,:Address of the register to write with LSB in BIT21. For simplicity, use the #defines in this same file.
u16ValueToWrite,:16-bit value to be written to the register.
pu8DataRead,:Pointer to where part's response should be stored.
cu8Protocol,:Communication protocol activated.
Returns:
Status. Clear when no error found, otherwise errors as defined in Miranda Exception codes.